#include <stdio.h>
#include <string.h>

#define STDIN
//#define DEBUG

char integer[1000];
int len;

int
main() {
#ifdef STDIN
    freopen("bin/1519.in", "r", stdin);
#endif

    int i;
    while(scanf("%s", integer) != EOF && integer[0] != '0') {
#ifdef DEBUG
        printf("%s\n", integer);
#endif
        int sum = 0;
        for (i = 0; integer[i] != '\0'; ++i) {
            sum += integer[i] - '0';
            if (sum > 9)
                sum = sum / 10 + sum % 10;
        }
        printf("%d\n", sum);
    }

    return 0;
}
